//  PULSAR, THE GAME
//  ================================
//  COPYRIGHT(c) 2013 BY KAMIL MRZYGŁÓD
//  CODENOVA.PL

define(function () {
    var bodyId = 'pulsarBody';
    var Core = function() {};

    Core.prototype = {

        /**
         * Creates HTML tag with given attributes
         * @param el
         * @param attributes
         * @constructor
         */
        CreateHtmlElement: function(el, attributes) {
            var tag = document.createElement(el);
            for(var attribute in attributes) {
                if(attributes.hasOwnProperty(attribute)) {
                    tag.setAttribute(attribute, attributes[attribute])
                }
            }
            document.getElementById(bodyId).appendChild(tag);
        },

        /**
         * Draws rectangle with given parameters
         * @param ctx
         * @param X
         * @param Y
         * @param width
         * @param height
         * @param background
         * @param borderColor
         * @param borderWidth
         * @constructor
         */
        DrawRectangle: function(ctx, X, Y, width, height, background, borderColor, borderWidth) {
            ctx.fillStyle = background;
            ctx.fillRect(X, Y, width, height);
            ctx.strokeStyle = borderColor;
            ctx.lineWidth = borderWidth;
            ctx.strokeRect(X, Y, width, height);
        },

        /**
         * Generates unique ID
         * @returns {string}
         * @constructor
         */
        GenerateUUID: function() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
                var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
                return v.toString(16);
            });
        },

        /**
         * Prepares given element for further drawing
         * @param el
         * @constructor
         */
        GetCanvasAndContext: function(el) {
            var canvas;

            canvas = document.getElementById(el.ElementId);
            // Set canvas for given element
            Object.defineProperties(el, {
                'Canvas': {
                    enumerable: true,
                    configurable: false,
                    writable: false,
                    value: canvas
                },
                'Context': {
                    enumerable: true,
                    configurable: false,
                    writable: false,
                    value: canvas.getContext('2d')
                }
            });
        },

        /**
         * Gets window dimensions
         * @returns {{Height: Number, Width: Number}}
         * @constructor
         */
        GetWindowDimensions: function() {
            return {
                Height: window.innerHeight,
                Width: window.innerWidth
            }
        }
    };

    return Core.prototype;
});